<template>
  <div class="cartcontrol">
    <transition name="move">
      <div @click.stop.prevent="decreaseCart" class="cart-decrease" v-show="food.count>0">
        <span class="inner icon-remove_circle_outline"></span>
      </div>
    </transition>
    <div class="cart-count" v-show="food.count>0">{{food.count}}</div>
    <div class="cart-add icon-add_circle" @click.stop.prevent="addCart"></div>
  </div>
</template>

<script>
  import Vue from 'vue';

  export default {
    props: {
      food: {
        type: Object
      }
    },
    methods: {
      addCart(event) {
        if (!this.food.count) {
          // 通过Vue.set方法可以观测到数据变更
          Vue.set(this.food, 'count', 1)
        } else {
          this.food.count++
        }
        this.Event.$emit('cartAdd', event.target);
      },
      decreaseCart() {
        if (this.food.count) {
          this.food.count--
        }
      }
    },
    created() {
    }
  }
</script>

<style lang="stylus" rel="stylesheet/stylus" scoped>
  .cartcontrol
    font-size: 0
    .cart-decrease
      display: inline-block
      padding: 6px
      .inner
        line-height: 24px
        font-size: 24px
        color: rgb(0, 160, 220)
        transform: rotate(0deg)
    .cart-count
      display: inline-block
      vertical-align: top
      width: 12px
      font-size: 10px
      padding-top: 6px
      line-height: 24px
      color: rgb(147, 153, 159)
    .cart-add
      display: inline-block
      padding: 6px
      line-height: 24px
      font-size: 24px
      color: rgb(0, 160, 220)
  .move-enter-active, .move-leave-active
    transition: all 0.2s linear
  .move-enter, .move-leave-to
    opacity: 0
    transform: translate3d(24px, 0, 0) rotate(180deg)

</style>
